﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using YArchitech.LIB;
using YArchitech.MEP.Electric.Common;

namespace YArchitech.Revit.Electric.Common
{
	public class FamilyConfig
	{
		public FamilyConfig(string name)
		{
			this.dbTableName = name;
			this.parameters = new List<DbParameter>();
		}

		public List<DbParameter> Parameters
		{
			get
			{
				return this.parameters;
			}
		}

		public void GetParameterConfig()
		{
			string text = Path.Combine(Product.DataLocation, "ElectricalData", "FamilyConfig.xml");
			if (!File.Exists(text))
			{
				return;
			}
			foreach (XmlElement xmlElement in new YArchitech.MEP.Electric.Common.XmlHelper(text, "FamilyLib").GetElements(this.dbTableName))
			{
				DbParameter dbParameter = new DbParameter();
				dbParameter.Name = xmlElement.Name;
				dbParameter.SharedName = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "SharedName");
				dbParameter.Unit = YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "Unit");
				dbParameter.ReadOnly = Convert.ToBoolean(YArchitech.MEP.Electric.Common.XmlHelper.GetAttribute(xmlElement, "ReadOnly"));
				this.parameters.Add(dbParameter);
			}
		}

		private const string sharedName = "SharedName";

		private const string unit = "Unit";

		private const string readOnly = "ReadOnly";

		private string dbTableName = string.Empty;

		private List<DbParameter> parameters;
	}
}
